Machine Learning Tutorial

by: titlelost, 7 years ago

Last edited: 7 years ago

Hello,

I'm working on the machine learning tutorial. I'm new to python, but I thought the ML tutorial would be a good place to learn.

In the tutorial, the script is supposed to return 30 values, but mine is returning 33.

I've included some code below. Am I working with a different data set or is my script shot?

import quandl, math
import numpy as np
import pandas as pd
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression

df = quandl.get('WIKI/GOOGL')
df = df[['Adj. Open','Adj. High','Adj. Low','Adj. Close','Adj. Volume',]]
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) / df['Adj. Close']
df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open']

df = df[['Adj. Close','HL_PCT','PCT_change','Adj. Volume']]
forecast_col = 'Adj. Close'
df.fillna(value=-99999,inplace=True)
forecast_out=int(math.ceil(0.01*len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)

X = np.array(df.drop(['label'],1))
X = preprocessing.scale(X)
X = X[:-forecast_out]
X_lately = X[-forecast_out:]

df.dropna(inplace=True)
y = np.array(df['label'])
y = np.array(df['label'])

X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size =0.2)

clf=LinearRegression()
clf.fit(X_train, y_train)
accuracy = clf.score(X_test,y_test)




You must be logged in to post. Please login or register an account.